home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / MacODBC / ODBC Tools / SampleDriver / CONNECT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-16  |  3.3 KB  |  162 lines  |  [TEXT/MPS ]

  1.  
  2.     /*
  3.     ** CONNECT.C - This is the module containing the code for ODBC for
  4.     ** allocation and connection.
  5.     **
  6.     ** (C) Copyright 1991, 1992 By Microsoft Corp.
  7.     */
  8.  
  9. #include "sample.h"
  10. #include <Memory.h>
  11.  
  12.  
  13.     //    Allocate an ODBC Driver environment (ENV) block.
  14.  
  15.  
  16. SQL_PRE_API RETCODE SQL_API
  17. SQLAllocEnv(
  18.     HENV   FAR *phenv)
  19. {
  20.     HENV    henv;
  21.  
  22.     henv = (HENV)NewHandleClear( sizeof( ENV ) );
  23.     if( henv )
  24.         HLock( (Handle)henv );
  25.     else
  26.     {
  27.         *phenv = SQL_NULL_HENV;
  28.         return SQL_ERROR;
  29.     }
  30.     *phenv = henv;
  31.     return SQL_SUCCESS;
  32. }/* end SQLAllocEnv */
  33.  
  34.  
  35.     //    Allocate a DBC block.
  36.  
  37. SQL_PRE_API RETCODE SQL_API
  38. SQLAllocConnect(
  39.     HENV        lpenv,
  40.     HDBC   FAR *phdbc)
  41. {
  42.     HDBC    hdbc;
  43.  
  44.  
  45.     hdbc = (HDBC)NewHandleClear( sizeof( DBC ) );
  46.     if( hdbc )
  47.         HLock( (Handle)hdbc );
  48.     else
  49.     {
  50.         *phdbc = SQL_NULL_HDBC;
  51.         return SQL_ERROR;
  52.     }
  53.     *phdbc = hdbc;
  54.     return SQL_SUCCESS;
  55. }/* end SQLAllocConnect */
  56.  
  57.  
  58. SQL_PRE_API RETCODE SQL_API
  59. SQLConnect(
  60.     HDBC        hdbc,
  61.     UCHAR  FAR *szDSN,
  62.     SWORD       cbDSN,
  63.     UCHAR  FAR *szUID,
  64.     SWORD       cbUID,
  65.     UCHAR  FAR *szAuthStr,
  66.     SWORD       cbAuthStr)
  67. {
  68. //debugstr( "Sample Driver: SQLConnect" );
  69.     return SQL_SUCCESS;
  70. }/* end SQLConnect */
  71.  
  72.  
  73.     //    This function as its "normal" behavior is supposed to bring up a
  74.     //    dialog box if it isn't given enough information via "szConnStrIn".  If
  75.     //    it is given enough information, it's supposed to use "szConnStrIn" to
  76.     //    establish a database connection.  In either case, it returns a
  77.     //    string to the user that is the string that was eventually used to
  78.     //    establish the connection.
  79.  
  80. SQL_PRE_API RETCODE SQL_API
  81. SQLDriverConnect(
  82.     HDBC        hdbc,
  83.     HWND        hwnd,
  84.     UCHAR  FAR *szConnStrIn,
  85.     SWORD       cbConnStrIn,
  86.     UCHAR  FAR *szConnStrOut,
  87.     SWORD       cbConnStrOutMax,
  88.     SWORD  FAR *pcbConnStrOut,
  89.     UWORD       fDriverCompletion)
  90. {
  91.     short    iRet;
  92.     BOOL    fPrompt = FALSE;
  93.  
  94.     if(  (szConnStrIn == NULL)    || (!cbConnStrIn)
  95.      || ((cbConnStrIn == SQL_NTS) && (!szConnStrIn[0])) )
  96.         fPrompt = TRUE;
  97.     else
  98.     {        //  Check connection string for completeness
  99.         if( fDriverCompletion == SQL_DRIVER_COMPLETE
  100.          || fDriverCompletion == SQL_DRIVER_PROMPT )
  101.             fPrompt = TRUE;
  102.     }
  103.     if( fPrompt )
  104.     {
  105.             //    It is not necessary to call "MakeProcInstance" if you
  106.             //    generate a dialog box from a DLL.
  107.  
  108. //mj    iRet = DialogBox( s_hModule, "EDRIVERCONNECT", pGrafPort, FDriverConnectProc );
  109. iRet = 333;    //mj
  110.         if( (!iRet) || (iRet == -1) )
  111.             return SQL_NO_DATA_FOUND;
  112.     }
  113.     return SQL_SUCCESS;
  114. }/* end SQLDriverConnect */
  115.  
  116.  
  117. SQL_PRE_API RETCODE SQL_API
  118. SQLBrowseConnect(
  119.     HDBC        hdbc,
  120.     UCHAR  FAR *szConnStrIn,
  121.     SWORD       cbConnStrIn,
  122.     UCHAR  FAR *szConnStrOut,
  123.     SWORD       cbConnStrOutMax,
  124.     SWORD  FAR *pcbConnStrOut)
  125. {
  126. //debugstr( "Sample Driver: SQLBrowseConnect" );
  127.     return SQL_SUCCESS;
  128. }/* end SQLBrowseConnect */
  129.  
  130.  
  131. SQL_PRE_API RETCODE SQL_API
  132. SQLDisconnect(
  133.     HDBC        hdbc)
  134. {
  135. //debugstr( "Sample Driver: SQLDisconnect" );
  136.     return SQL_SUCCESS;
  137. }/* end SQLDisconnect */
  138.  
  139.  
  140. SQL_PRE_API RETCODE SQL_API
  141. SQLFreeConnect(
  142.     HDBC        hdbc)
  143. {
  144.  
  145. //debugstr( "Sample Driver: SQLFreeConnect" );
  146.     HUnlock( (Handle)hdbc );
  147.     DisposHandle( (Handle)hdbc );
  148.     return SQL_SUCCESS;
  149. }/* end SQLFreeConnect */
  150.  
  151.  
  152. SQL_PRE_API RETCODE SQL_API
  153. SQLFreeEnv(
  154.     HENV        henv)
  155. {
  156.  
  157. //debugstr( "Sample Driver: SQLFreeEnv" );
  158.     HUnlock( (Handle)henv );
  159.     DisposHandle( (Handle)henv );
  160.     return SQL_SUCCESS;
  161. }/* end SQLFreeEnv */
  162.